#define MAXROM 0x800
#define MAXRAM 0x100
#define MAXSTACK 5

typedef unsigned char bool;
typedef unsigned char byte;
typedef unsigned short romaddr;
typedef unsigned short word;
typedef unsigned int uint;


#define STATUS_C   0x01
#define STATUS_AC  0x02
#define STATUS_Z   0x04
#define STATUS_SP  0x08
#define STATUS_WT  0x10
#define STATUS_PG0 0x20
#define STATUS_PG1 0x40
#define STATUS_PG  0x60
#define STATUS_GB 0x80


#define OPTION_LVD_EN    0x01 
#define OPTION_LVD_SEL    0x02
#define OPTION_TURBO_EN    0x04
#define OPTION_ONE_CYC    0x08
#define OPTION_PSEX_EN    0x10
#define OPTION_PWSV_EN    0x20
#define OPTION_IOWM 	0x40
#define OPTION_RAMB   0x80

#define ADF_AINTF	0X40
#define ADF_ARDY	0X80

extern romaddr pc;
extern byte acc;

extern romaddr stack [MAXSTACK];
extern byte ram[4][0x20];
extern romaddr rom[4][0x200];
extern byte implicit_registers[8];

extern byte *ind ;
extern byte *tcr;
extern byte *pcl;
extern byte *sfr;
extern byte *mir;
extern byte *rpa;
extern byte *rpb;
extern byte *rpc;

extern byte *p2d;
extern byte *p3d;
extern byte *pwc;
extern byte *adf;
extern byte *add;
extern byte *adh;
extern byte *adc;

extern byte *wtc;
extern byte *tcc;
extern byte *ipa;
extern byte *opt;
extern byte *hgr;
extern byte *cpa;
extern byte *cpb;
extern byte *cpc;

extern romaddr pc;
extern byte acc;


typedef enum
{
    STATE_RUNNING,              /* normal running */
    STATE_STOPPED,              /* stopped, not running */
    STATE_BREAK_PT,             /* at a break point */
    STATE_SLEEP,                /* Sleep mode (there are many sleep modes. */
} StateType;

typedef struct _CrCore CRCore;

struct _CrCore
{
    int state;                  /* What state is the device in */
    int sleep_mode;             /* If in sleep state, what mode? */
    romaddr PC;                 /* Program Counter */
    romaddr PC_size;            /* size of Program Counter in bytes */
    romaddr PC_max;             /* maximum value PC can hold for a given
                                   device (is flash_sz/2) */
};

/* in crdis.c: */
char* disassemble_inst(word opcode, char *buffer);

/* crinst.c */
void decode(romaddr opcode);
void instruction_incr(void);
/* in debug.c: */

extern int trace;
extern int run;
extern int step;
extern int quit;
extern int ignore_break;

//void init_debug (void);
void debug (void);
//void dobreak (void);

extern unsigned long cyclenumble ;
extern unsigned long instruction_numble;
byte read_reg_abs (byte addr);
void write_reg_abs (byte addr, byte data);

void push (romaddr addr);
romaddr pop (void);

typedef struct _bpList bpList;

struct _bpList
{
		word data;
		uint count;
		bool disable;
		bpList *next;
};

extern bpList *bplist;
extern bpList *bpstepover;

bpList* bp_list_prepend(bpList *list, word data,uint count);
bpList* bp_list_find(bpList* list,word data);
bpList* bp_list_remove(bpList* list,word data);
bpList *bp_list_remove_all(bpList *list);

#define snprintf  _snprintf
#ifndef strcasecmp
#define strcasecmp  stricmp
#endif
#define strncasecmp strnicmp

